﻿
using System ;

using MskEdit.Dxf.Model ;
using MskEdit.Sdk ;


namespace MskEdit.Dxf.Backend
{

    public static class DxfSymbolTablesReader
    {
                
        internal static DxfTables TryRead( string[] allLines, ref int lineNo, DxfTables fallbackTables ) {
            
            int internalLineNo = lineNo ;

            if ( DxfLineReader.TryRead( "2", "TABLES", allLines, ref internalLineNo, null ) == null ) 
                return fallbackTables ;
        
            DxfTables dxfTables = new DxfTables( allLines, new SdkSubrange(0,0) ) ; // Dummy
            
            while ( internalLineNo < allLines.Length ) {
                            
                DxfTable dxfTable = DxfSymbolTableReader.TryRead( allLines, ref internalLineNo, null ) ;
                if ( dxfTable != null ) {
                    dxfTables.AddTable( dxfTable ) ;
                    System.Diagnostics.Debug.WriteLine( dxfTable ) ;
                    continue ;
                }
                
                break ;
            }

            lineNo = internalLineNo ;
             
            return dxfTables ;
        }


    }
}
